// pages/mine/pages/praise/praise.js
const app = getApp()
const http = require("../../../../utils/http.js")
const util = require("../../../../utils/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 1,
    pageSize: 10,
    totalPage: 0,

    mddList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  initDate() {
    let that = this;
    that.setData({
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0
    })
    let param = {
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
      openid: wx.getStorageSync("tokenId")
    }
    http.get("/attention/getByCondition", param)
      .then(res => {
        if (res.data.status == 200) {
          let mddList = res.data.data.resultList
          mddList.forEach((item) => {
            // let time = new Date()
            item.record.createTime = util.timeFormat(item.record.createTime)
          })
          that.setData({
            totalPage: res.data.data.totalPage,
            mddList: mddList
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1500
          })
        }
      })
  },
  addData() {
    let that = this;
    if (thta.data.pageIndex >= that.data.totalPage) {
      return;
    }
    that.setData({
      pageIndex: ++that.data.pageIndex,
      pageSize: 10
    })
    let param = {
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
      openid: wx.getStorageSync("tokenId")
    }
    http.get("/attention/getByCondition", param)
      .then(res => {
        if (res.data.status == 200) {
          let mddList = res.data.data.resultList
          mddList.forEach((item) => {
            let dataee = util.timeFormat(item.record.createTime)
            item.record.createTime = dataee
          })
          mddList = mddList.concat(that.data.mddList)
          that.setData({
            totalPage: res.data.data.totalPage,
            mddList: mddList
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1500
          })
        }
      })
  },

  tolower() {
    this.addData();
  },
  toMddDetail(e) {
    let mddId = e.currentTarget.dataset.mddid
    wx.navigateTo({
      url: '/pages/destination/views/detail/detail?mddId=' + mddId,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.initDate();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})